/**
 * @description a simple js framework
 * @author adam
 */
var _ = {
	getById : function(id) {
            return document.getElementById(id);
	}
	,getByTag : function(tagName) {
	    return document.getElementsByTagName;
	}
	,getByClass : function(className, parent) {
		if ( document.getElementsByClassName ) {
			return document.getElementsByClassName(className);
		} else {
			parent = parent || document;
			var eleLists =  parent.getElementsByTagName('*');
			var results = [];
			for ( var i = 0, l = eleLists.length; i < l; i++ ) {
	            if ( eleLists[i].className.indexOf(className) != '-1' ) {
					results.push(eleLists[i]);
				}
            }
			console.log(results);
			return results;
		}
	}
	,setStyle : function(elm,css) {
		for ( var prop in css ) {
			css.hasOwnProperty(prop) && (elm.style[prop] = css[prop]);
		}
	}
	,typeOf : function(object) {
	    var _t;
            return ( (_t=typeof(object))=='object' ? (object==null && 'null') || Object.prototype.toString.call(object).slice(8,-1)
		                                : _t).toLowerCase();
	}
	// format('%1 want to know whose %2 you %3', 'I', 'shirt', 'wear')
	,format : function(string) {
	    var args = arguments;
	    var pattern = new RegExp('%([1-' + args.length + '])', 'g');
	    return String(string).replace(pattern, function(match, index) {
		    return args[index];
	    });
	}
};
var getElementsByClassName = function (searchClass, node,tag) {
    if(document.getElementsByClassName){
        return  document.getElementsByClassName(searchClass)
    }else{
        node = node || document;
        tag = tag || "*";
        var classes = searchClass.split(" "),
        elements = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag),
        patterns = [],
        returnElements = [],
        current,
        match;
        var i = classes.length;
        while(--i >= 0){
            patterns.push(new RegExp("(^|\\s)" + classes[i] + "(\\s|$)"));
        }
        var j = elements.length;
        while(--j >= 0){
            current = elements[j];
            match = false;
            for(var k=0, kl=patterns.length; k<kl; k++){
                match = patterns[k].test(current.className);
                if (!match)  break;
            }
            if (match)  returnElements.push(current); 
        }
        return returnElements;
    }
}